package com.jxtti.service;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jxtti.dao.UserDao;
import com.jxtti.model.User;


@Service
@Transactional(rollbackFor = { RuntimeException.class, Exception.class })
public class UserService {

	@Autowired
	private UserDao userDao;


	public User findUserByName(String userName) {
		return userDao.findUserByName(userName);
	}
	
	/**
	 * 获取页面上的用户信息列表
	 * 
	 * @param data
	 * @return
	 */
	public PageInfo<User> getUserList(Map<String, String> data) {
		// 第几页
		int pageNum = Integer.parseInt((data.get("page") == null || data.get(
				"page").equals("0")) ? "1" : data.get("page"));
		// 每页显示条数 
		int pageSize = Integer.parseInt((data.get("rows") == null || data.get(
				"rows").equals("0")) ? "10" : data.get("rows"));

		PageHelper.startPage(pageNum, pageSize);
		PageInfo<User> page = new PageInfo<User>(userDao.getUserList(data));
		return page;
	}
	
	
	public List<User> getUserListForWeb(Map<String, String> data) {
		
		return userDao.getUserList(data);
		
	}
	
	
	
	
}
